package com.fulin.sycnLife;

import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExchangerTest {
	private static final Exchanger<String> exgr = new Exchanger<String>();

	private static ExecutorService threadPool = Executors.newFixedThreadPool(2);
	
	public static void main(String[] args) {
		threadPool.execute(new Runnable(){

			@Override
			public void run() {
				try{
					String A = "银行流水A";//A录入的银行流水
					exgr.exchange(A);
				}catch(InterruptedException e){
				}
			}
		});
		
		threadPool.execute(new Runnable(){

			public void run() {
				try{
					String B = "银行流水B";//B录入的银行流水
					String A = exgr.exchange("B");
					System.out.println("A和B数据是否一致: "+ A.equals(B) + " , A录入的数据是 : "+ A + " ,B录入的数据是 : "+ B);
				}catch(InterruptedException e){
				}
			}
			
		});
		
		threadPool.shutdown();
	}
}
